package com.zzw.mvvm.base;

import android.util.Log;

import com.zzw.mvvm.beans.base.StatusPJ;
import com.zzw.mvvm.utils.rxutils.RxEventManager;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class BaseViewModel extends ViewModel {
    private RxEventManager rxEventManager;
    private MutableLiveData<StatusPJ> currentStatus;
    StatusPJ statusPJ = null;

    public BaseViewModel() {
        this.rxEventManager = new RxEventManager();
    }

    public MutableLiveData<StatusPJ> getCurrentStatus() {
        if (currentStatus == null) {
            currentStatus = new MutableLiveData<>();
        }
        return currentStatus;
    }

    public void setCurrentStatus(int currentCode, String msg) {
        if (statusPJ == null) {
            statusPJ = new StatusPJ();
        }
        statusPJ.setCode(currentCode);
        statusPJ.setMsg(msg);
        currentStatus.setValue(statusPJ);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        if (rxEventManager != null) {
            rxEventManager.clearAllRxEvent();
        }
        Log.i("BaseViewModel", "BaseViewModel ->onCleared");
    }
}
